<style type="text/css">
    table {
        max-width: 750px;
    }
</style>
<div style="min-height: 400px;">
    <table id="listgaleri" style="margin-top: 1em;">
        <thead>
            <tr>
                <th>Waktu Posting</th>
                <th>Jenis</th>
                <th>Judul</th>
                <th>Preview</th>
                <th>Status</th>
            </tr>
        </thead>
        <tbody>
            <?php
            if (count($galList) > 0) {
                foreach ($galList as $galeri) {
                    echo "<tr>";
                    echo "<td style='text-align: right;'>" . $galeri->posted_date . "<br />" . $galeri->posted_time . "</td>";
                    echo "<td>" . $galeri->jenis . "</td>";
                    echo "<td>" . $galeri->judul . "</td>";
                    echo "<td>" . "<a href='javascript:void(0);' onClick='javascript:showPrev(" . $galeri->id . ", \"" . $galeri->type . "\", \"" . $galeri->src . "\", \"" . $galeri->judul . "\")'>" . "Lihat" . "</a>" . "</td>";
                    echo "<td>" . ($galeri->is_approved ? "Approved" : "Pending Approval") . "</td>";
                    echo "</tr>";
                }
            } else {
                echo "<tr>";
                echo "<td style='text-align: center;' colspan='5'>" . "(tidak ada history entry galeri)" . "</td>";
                echo "</tr>";
            }
            ?>
        </tbody>
    </table>
</div>
<div id="prev_img_dialog" style="display: none;" title="Preview">
    <div>
        <h1></h1>
    </div>
    <br />
    <div>
        <img src="#" />
    </div>
</div>
<input type="hidden" id="galitem_id" value="0" />
<script type="text/javascript">
    jQuery(document).ready(function() {
        $("#prev_img_dialog").dialog({
            modal: true,
            autoOpen: false,
            width: 650,
            buttons: {
                "Batal": function() {
                    $(this).dialog("close");
                },
                "Simpan": function() {
                    if (confirm("Publish entry galeri?")) {
                        $.ajax({
                            type: "POST",
                            url: "<?php echo site_url("galeri/updateApprove"); ?>",
                            async: false,
                            data: {
                                id: $("#galitem_id").val()
                            },
                            beforeSend: function(xhr) {
                            },
                            success: function(result, status, xhr) {
                                window.location = "<?php echo site_url("usercp/auditgal"); ?>";
                            },
                            error: function(xhr, status, error) {
                                window.location = "<?php echo site_url("usercp/auditgal"); ?>";
                            }
                        });
                    }
                },
                "Tolak": function() {
                    if (confirm("Tolak entry galeri?")) {
                        $.ajax({
                            type: "POST",
                            url: "<?php echo site_url("galeri/delete"); ?>",
                            async: false,
                            data: {
                                id: $("#galitem_id").val()
                            },
                            beforeSend: function(xhr) {
                            },
                            success: function(result, status, xhr) {
                                window.location = "<?php echo site_url("usercp/auditgal"); ?>";
                            },
                            error: function(xhr, status, error) {
                                window.location = "<?php echo site_url("usercp/auditgal"); ?>";
                            }
                        });
                    }
                }
            }
        });
    });
    function showPrev(id, type, src, title) {
        $("#galitem_id").val(id);
        switch (type) {
            case "IMG" :
                $("#prev_img_dialog h1").text(title);
                $("#prev_img_dialog img").prop("src", src);
                $("#prev_img_dialog").dialog("open");
                break;
        }
    }
</script>